﻿#include "palette.h"

Palette::Palette(QWidget* parent)
	: QWidget(parent)
{
	QHBoxLayout* main_hlay = new QHBoxLayout;

	chart_picker = new Picker;
	chart_picker->setStyleSheet("background-color:pink;");
	chart_picker->setFixedWidth(250);
	chart_canvas = new Canvas;
	connect(chart_picker, &Picker::startCreate, chart_canvas, [=]
		{
			Shape* shape_create = Picker::getShape(chart_picker->getSelectShape()->getType());
			shape_create->setParent(this);
			shape_create->setShapeWidth(100);
			shape_create->setShapeHeight(shape_create->getWidth() / shape_create->getRate());
			chart_canvas->getShapeManager()->recordShape(shape_create, ShapeManager::CreateMode::Edit);
			chart_canvas->update();
		});
	connect(chart_picker, &Picker::resetCreate, chart_canvas, [=](const QPoint& point) {
		chart_canvas->getShapeManager()->recordShape(nullptr, ShapeManager::CreateMode::Move, point);
		chart_canvas->update();
		});
	connect(chart_picker, &Picker::finalCreate, chart_canvas, [=] {
		chart_canvas->getShapeManager()->recordShape(nullptr, ShapeManager::CreateMode::Save);
		chart_canvas->update();
		});
	connect(chart_picker, &Picker::pauseCreate, chart_canvas, [=] {
		chart_canvas->getShapeManager()->recordShape(nullptr, ShapeManager::CreateMode::Edit);
		chart_canvas->update();
		});
	main_hlay->addWidget(chart_picker);
	main_hlay->addWidget(chart_canvas);
	setLayout(main_hlay);
}
